package cc.site.main.controller;

import cc.site.common.utils.R;
import cc.site.main.bean.dto.PetDto;
import cc.site.main.service.TblPetService;
import cn.hutool.core.collection.ListUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.List;
import java.util.Random;

/**
 * @CREATE By yangruomao On 2024/5/6 上午1:24
 */
@RestController
@RequestMapping("/recommended")
@Api(tags = "推荐系统")
public class RecommendedController {

    @Autowired
    private TblPetService petService;


    @ApiOperation("推荐宠物【返回一个分页（偷偷的打乱顺序然后返回全部）】")
    @GetMapping("/{limit}")
    public R recommended(@PathVariable Integer limit) {
        List<PetDto> pets = petService.all();
        Collections.shuffle(pets);
        List<List<PetDto>> split = ListUtil.split(pets, limit);
        return R.ok().data("page", split);
    }
}
